import pytest

from config import BASE_URL
from page.page_login import LoginPage
from tools import DriverTools, read_json


class TestLogin(object):

    def setup_method(self):
        # 打开浏览器

        self.driver = DriverTools.get_driver()
        # 输入网址
        self.driver.get(BASE_URL + '/common/member/login')
        # 输入手机号 密码 验证码.....
        self.reg = LoginPage(self.driver)

    def teardown_method(self):
        # 关闭浏览器
        DriverTools.quit_driver()


    arg_names = "phone,pwd,expect,img"

    @pytest.mark.parametrize(arg_names, read_json("login_data.json"))
    def test_login(self, phone, pwd, expect, img):
        # 调用方法：只考虑页面怎么操作的
        self.reg.login(phone, pwd)
        # 打印结果
        if phone == "13800000001":
            result = self.reg.get_login_result()
        else:
            result = self.reg.get_uesr_not()
        print(result)
        # 断言结果
        assert expect in result
        self.reg.get_shot(img)

    # def test01_reg_login(self):
    #     self.reg.login('1380013828', 'w123456')
    #     result = self.reg.get_login_result()
    #     assert '安享智慧理财' in result
    #     print(result)
    #     self.reg.get_shot('pwd_error2.png')
    #
    # def test02_fail_login(self):
    #     self.reg.login('1380013828', 'w123456')
    #     result = self.reg.get_uesr_not()
    #     assert '用户不存在' in result
    #     print(result)
    #     self.reg.get_shot('pwd_error3.png')